package leetcode;

/**
 * @Description 1190. 反转每对括号间的子串
 * @Author away
 * @Version V1.0.0
 * @Since 1.0
 * @Date 21.5.26
 */

public class T1190 {
    public static void main(String[] args) {
        T1190 t1190 = new T1190();
        String s = t1190.reverseParentheses("(u(love)i)");
        System.out.println(s);
    }

    public String reverseParentheses(String s) {
        String result = "";
        int start;
        while ((start = s.lastIndexOf("(")) != -1) {
            int end = s.indexOf(")", start);
            s = s.substring(0, start) + reverse(s.substring(start + 1, end)) + s.substring(end + 1, s.length());
        }
        return s;
    }

    public String reverse(String s) {
        StringBuilder sb = new StringBuilder();
        for (int i = s.length() - 1; i >= 0; i--) {
            sb.append(s.charAt(i));
        }
        return sb.toString();
    }
}
